package com.sec.android.app.myfiles.module.feature.privatemode;

import com.sec.android.app.myfiles.MyFilesTestRunner;
import com.sec.android.app.myfiles.feature.PrivateModeMgr;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.shadow.custom.ShadowAppFeatures;
import com.sec.android.app.myfiles.shadow.sem.ShadowSemPrivateModeManager;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;


@RunWith(MyFilesTestRunner.class)
public class testPrivateModeMgr {
    PrivateModeMgr mPrivateModeMgr;

    @Before
    public void setUp() throws Exception {
        ShadowSemPrivateModeManager.init();
        ShadowAppFeatures.init();
        mPrivateModeMgr = PrivateModeMgr.getInstance(RuntimeEnvironment.application);
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testGetInstance() {
        Assert.assertNotNull(mPrivateModeMgr);
    }

    @Test
    public void testIsPrivateMode() {
        Assert.assertTrue(mPrivateModeMgr.isPrivateMode());

        ShadowSemPrivateModeManager.mPrivateMode = false;
        Assert.assertFalse(mPrivateModeMgr.isPrivateMode());
    }

    @Test
    public void testIsPrivateDirMounted() {
        Assert.assertTrue(mPrivateModeMgr.isPrivateDirMounted());

        ShadowSemPrivateModeManager.mStorageMounted = false;
        Assert.assertFalse(mPrivateModeMgr.isPrivateDirMounted());
    }

    @Test
    public void testIsReady() {
        Assert.assertTrue(mPrivateModeMgr.isReady());

        ShadowSemPrivateModeManager.mIsReady = false;
        Assert.assertFalse(mPrivateModeMgr.isReady());
    }

    @Test
    public void testGetRootDir() {
        Assert.assertEquals(AppConstants.StoragePath.PRIVATE_ROOT, mPrivateModeMgr.getRootDir());
    }


    @Test
    public void testIsEnabled() {
        Assert.assertFalse(mPrivateModeMgr.isEnabled());

        ShadowAppFeatures.mAndroidForWork = false;
        Assert.assertFalse(mPrivateModeMgr.isEnabled());

        ShadowAppFeatures.mIsKnox = false;
        Assert.assertTrue(mPrivateModeMgr.isEnabled());

        ShadowSemPrivateModeManager.mPrivateMode = false;
        Assert.assertFalse(mPrivateModeMgr.isEnabled());
    }


    @Test
    public void testIsPrivateModePath() {
        Assert.assertFalse(mPrivateModeMgr.isPrivateModePath("/mnt/test"));
        Assert.assertTrue(mPrivateModeMgr.isPrivateModePath(AppConstants.StoragePath.PRIVATE_ROOT));
        Assert.assertTrue(mPrivateModeMgr.isPrivateModePath(AppConstants.StoragePath.PRIVATE_ROOT + "/test"));
    }


}
